package com.dxy.df.modules.controller;

import java.util.List;

import com.dxy.df.core.assit.SearchHandler;
import com.dxy.df.core.model.PageRs;
import com.dxy.df.core.model.Rs;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.dxy.df.modules.bean.entity.UserAcceptRiceRecordEntity;
import com.dxy.df.modules.bean.vo.UserAcceptRiceRecordVo;
import com.dxy.df.modules.bean.query.UserAcceptRiceRecordQuery;
import com.dxy.df.modules.bean.put.UserAcceptRiceRecordPut;
import com.dxy.df.modules.service.UserAcceptRiceRecordService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;
/**
 * 收饭记录
 * @author biz@dxy.cn
 * @date 2019-10-25 15:36:06
 */
@Api(tags="收饭记录")
@RestController
@RequestMapping("/api/users/accept/rice/record")
public class UserAcceptRiceRecordController {
	@Autowired
	private UserAcceptRiceRecordService userAcceptRiceRecordService;
	@Autowired
	private SearchHandler searchHandler;

    @ApiOperation(value = "收饭记录分页列表")
	@PostMapping("/search")
	public PageRs<UserAcceptRiceRecordVo> search(
			@RequestBody @Valid UserAcceptRiceRecordQuery query){
		//查询列表数据
        List<UserAcceptRiceRecordVo> voList =  userAcceptRiceRecordService.queryList(query);
        int total = userAcceptRiceRecordService.queryTotal(query);
		return searchHandler.search(voList,total,query);
	}
	

    @ApiOperation(value = "收饭记录信息")
	@GetMapping("/info/{id}")
	public Rs<UserAcceptRiceRecordVo> info(@PathVariable("id") Integer id){
		UserAcceptRiceRecordQuery query = new UserAcceptRiceRecordQuery();
        query.setId(id);
		UserAcceptRiceRecordEntity userAcceptRiceRecord = userAcceptRiceRecordService.queryObject(query);

        return buildResponseVo(userAcceptRiceRecord);
	}

    @ApiOperation(value = "收饭记录新增")
	@PostMapping
	public Rs save(@RequestBody UserAcceptRiceRecordPut userAcceptRiceRecord){
		userAcceptRiceRecordService.save(userAcceptRiceRecord);
		return Rs.ok();
	}

    @ApiOperation(value = "收饭记录修改")
	@PutMapping
	public Rs update(@RequestBody UserAcceptRiceRecordPut userAcceptRiceRecord){
		userAcceptRiceRecordService.update(userAcceptRiceRecord);
		return Rs.ok();
	}

    @ApiOperation(value = "收饭记录删除")
	@DeleteMapping
	public Rs delete(@RequestParam Integer[] ids){
		userAcceptRiceRecordService.deleteBatch(ids);
		return Rs.ok();
	}


	private Rs<UserAcceptRiceRecordVo> buildResponseVo(UserAcceptRiceRecordEntity entity) {
		UserAcceptRiceRecordVo vo = null;
		if (null != entity) {
			vo = new UserAcceptRiceRecordVo();
			BeanUtils.copyProperties(entity, vo);
		}
		return Rs.ok().putData(vo);
	}


}
